var Dawn = {
    ctxPath: "${ctxPath}",
    api: "${app.api}",
    inputTreeEventMap: {},
    confirm: function (tip, ensure) {//询问框
        parent.layer.confirm(tip, {
            btn: ['确定', '取消']
        }, function (index) {
            ensure();
            parent.layer.close(index);
        }, function (index) {
            parent.layer.close(index);
        });
    },
    deleteConfirm: function (tip, ensure) {//询问框
        parent.layer.confirm(tip, {
            title: "删除提示",
            btn: ['确定', '取消']
        }, function (index) {
            ensure();
            parent.layer.close(index);
        }, function (index) {
            parent.layer.close(index);
        });
    },
    log: function (info) {
        console.log(info);
    },
    alert: function (info, iconIndex) {
        parent.layer.msg(info, {
            icon: iconIndex
        });
    },
    info: function (info) {
        Dawn.alert(info, 0);
    },
    success: function (info) {
        Dawn.alert(info, 1);
    },
    error: function (info) {
        Dawn.alert(info, 2);
    },
    showInputTree: function (inputTreeContentId) {
        let inputTreeContent = $("#" + inputTreeContentId);
        var onBodyDown;
        if(this.inputTreeEventMap[inputTreeContentId]) {
            onBodyDown = this.inputTreeEventMap[inputTreeContentId];
        } else {
            onBodyDown = function (event) {
                if (!(event.target.id == "menuBtn" || event.target.id == inputTreeContentId || $(event.target).parents("#" + inputTreeContentId).length > 0)) {
                    inputTreeContent.fadeOut("fast");
                    $("body").unbind("mousedown", onBodyDown);// mousedown当鼠标按下就可以触发，不用弹起
                    delete Dawn.inputTreeEventMap[inputTreeContentId];
                }
            };
        }
        this.inputTreeEventMap[inputTreeContentId] = onBodyDown;
        inputTreeContent.slideDown("fast");
        $("body").unbind("mousedown", onBodyDown).bind("mousedown", onBodyDown);
    },
    hideInputTree: function (inputTreeContentId) {
        let inputTreeContent = $("#" + inputTreeContentId);
        inputTreeContent.fadeOut("fast");
        $("body").unbind("mousedown", this.inputTreeEventMap[inputTreeContentId]);// mousedown当鼠标按下就可以触发，不用弹起
        delete this.inputTreeEventMap[inputTreeContentId];
    },
    zTreeCheckedNodes: function (zTreeId) {
        var zTree = $.fn.zTree.getZTreeObj(zTreeId);
        var nodes = zTree.getCheckedNodes();
        var ids = "";
        for (var i = 0, l = nodes.length; i < l; i++) {
            ids += "," + nodes[i].id;
        }
        return ids.substring(1);
    },
    /**
     * 获取链接传值
     */
    getQueryValue: function (key) {
        var reg = new RegExp("(^|&)" + key + "=([^&]*)(&|$)", "i");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) return unescape(r[2]);
        return null;
    }
};
